"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getRect = getRect;

var _taro = _interopRequireDefault(require("@tarojs/taro"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * 获取 boundingClientRect
 *
 * @param ref 要获取矩形的 DOM Ref
 * @param selector 要获取矩形的 DOM 的选择器，会从 DOM Ref 下查找，不传则获取 ref 的矩形
 *
 * * @example
 * ```tsx
 * useReady(async () => {
 *    const rect = await getRect(ref);
 * });
 * ```
 */
function getRect( // eslint-disable-next-line @typescript-eslint/no-explicit-any
ref, selector) {
  return new Promise(function (resolve, reject) {
    if (!ref.current) {
      reject();
      return;
    }

    var query = _taro.default.createSelectorQuery();

    query.selectAll("#".concat(ref.current.uid).concat(selector ? " ".concat(selector) : '')).boundingClientRect(resolve).exec();
  });
}